package com.zs.chat.repository;

import com.zs.chat.entity.ChatUsersEntity;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author madison
 * @description
 * @date 2020/10/12 7:30 下午
 */
@Repository
public interface ChatUsersDao extends JpaRepository<ChatUsersEntity, Integer>{

    List<ChatUsersEntity> findByName(String name);

    @Query(value = "select u from ChatUsersEntity u")
    List<ChatUsersEntity> selectUsers(Pageable page);

    @Modifying
    @Query("update ChatUsersEntity c set c.name=?1 where c.id=?2")
    Integer modifyByIdAndUserId(String customerName,Integer id);

    @Modifying
    @Query("delete from ChatUsersEntity where id = ?1")
    void deleteByCustomerId(Integer id);
}
